//
//  ZYCTeachingAttendanceCell.m
//  ZDSC
//
//  Created by ZDTX on 2021/7/29.
//

#import "ZYCTeachingAttendanceCell.h"
#import "UIButton+Corner.h"
#import "ZYCTeachingAttendanceModel.h"

@interface ZYCTeachingAttendanceCell ()

@property (nonatomic, strong) UIView *bgWhiteView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *line;

@property (nonatomic, strong) UIButton *subjectButton;
@property (nonatomic, strong) UIButton *classButton;
@property (nonatomic, strong) UILabel *statusLabel;
@property (nonatomic, strong) UILabel *teacherLabel;
@property (nonatomic, strong) UILabel *timeLabel;

@end
@implementation ZYCTeachingAttendanceCell

- (void)setModel:(ZYCTeachingAttendanceModel *)model{
    _model = model;
    _titleLabel.text = model.title;
    [_subjectButton setTitle:model.subjectName forState:UIControlStateNormal];
    [_classButton setTitle:model.listenClassTypeName forState:UIControlStateNormal];
    [self.subjectButton sizeToFit];
    [self.subjectButton corner];
    
    [self.classButton sizeToFit];
    [self.classButton corner];
    _statusLabel.text = model.overFlagStr;
    
    if ([model.overFlag isEqualToString:@"before"]) {
        _statusLabel.backgroundColor = HEX_RGB(@"#EB9F28");
    }else if ([model.overFlag isEqualToString:@"doing"]) {
        _statusLabel.backgroundColor = HEX_RGB(@"#39A85B");
    }else if ([model.overFlag isEqualToString:@"after"]) {
        _statusLabel.backgroundColor = HEX_RGB(@"#B9B9B9");
    }

    _teacherLabel.text = [NSString stringWithFormat:@"授课老师: %@",model.userName];
    _timeLabel.text = [NSString stringWithFormat:@"授课时间: %@",model.mergeTime];
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.bgWhiteView];
        [self.bgWhiteView addSubview:self.titleLabel];
        [self.bgWhiteView addSubview:self.line];
        [self.bgWhiteView addSubview:self.subjectButton];
        [self.bgWhiteView addSubview:self.classButton];
        [self.bgWhiteView addSubview:self.teacherLabel];
        [self.bgWhiteView addSubview:self.statusLabel];
        [self.bgWhiteView addSubview:self.timeLabel];

        [self.bgWhiteView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(9.5f);
            make.right.equalTo(self.contentView).offset(-9.5f);
            make.top.bottom.equalTo(self.contentView);
        }];
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bgWhiteView).offset(9.5f);
            make.right.equalTo(self.bgWhiteView).offset(-9.5f);
            make.top.equalTo(self.bgWhiteView).offset(10.0f);
        }];
        
        [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bgWhiteView).offset(9.5f);
            make.right.equalTo(self.bgWhiteView).offset(-9.5f);
            make.top.equalTo(self.titleLabel.mas_bottom).offset(15.0f);
            make.height.mas_equalTo(1.0f);
        }];

        [self.subjectButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bgWhiteView).offset(9.5f);
            make.top.equalTo(self.line.mas_bottom).offset(18.5f);
        }];

        [self.classButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.subjectButton.mas_right).offset(9.5f);
            make.centerY.equalTo(self.subjectButton);
        }];
        
        [self.teacherLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bgWhiteView).offset(9.5f);
            make.top.equalTo(self.subjectButton.mas_bottom).offset(17.5f);
        }];
        
        [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bgWhiteView).offset(9.5f);
            make.top.equalTo(self.teacherLabel.mas_bottom).offset(15.0f);
            make.bottom.equalTo(self.bgWhiteView).offset(-10.5f);
        }];
        
        [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.bgWhiteView).offset(-9.5f);
            make.top.equalTo(self.line.mas_bottom).offset(13.5f);
            make.size.mas_equalTo(CGSizeMake(56.0f, 23.0f));
        }];
        


        
    }
    return self;
}


- (UIView *)bgWhiteView {
    if (!_bgWhiteView) {
        _bgWhiteView = [[UIView alloc] init];
        _bgWhiteView.backgroundColor = HEX_RGB(@"#FFFFFF");
        _bgWhiteView.layer.cornerRadius = 7.5;
        _bgWhiteView.layer.masksToBounds = YES;
    }
    return _bgWhiteView;
}
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [UILabel LabelWithFont:kSystemBoldFont(17) titleColor:HEX_RGB(kTitleThemeColor) textAlignment:ZZTextAlignmentLeft];
        _titleLabel.numberOfLines = 0;
    }
    return _titleLabel;
}

- (UILabel *)line {
    if (!_line) {
        _line = [[UILabel alloc] init];
        _line.backgroundColor = HEX_RGB(@"#EAEAEA");
    }
    return _line;
}

/*
 
 */
- (UIButton *)subjectButton {
    if (!_subjectButton) {
        _subjectButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _subjectButton.backgroundColor =HEX_RGB(@"#B9B9B9");
        [_subjectButton setTitleColor:HEX_RGB(kTitleWhiteColor) forState:UIControlStateNormal];
        _subjectButton.titleLabel.font = kCustomFont(@"PingFangSC-Light", 12.0f);
    }
    return _subjectButton;
}

- (UIButton *)classButton {
    if (!_classButton) {
        _classButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _classButton.backgroundColor =HEX_RGB(@"#B9B9B9");
        [_classButton setTitleColor:HEX_RGB(kTitleWhiteColor) forState:UIControlStateNormal];
        _classButton.titleLabel.font = kCustomFont(@"PingFangSC-Light", 12.0f);
    }
    return _classButton;
}
- (UILabel *)teacherLabel {
    if (!_teacherLabel) {
        _teacherLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Light", 14) titleColor:HEX_RGB(@"#888888") textAlignment:ZZTextAlignmentLeft];
    }
    return _teacherLabel;
}

- (UILabel *)timeLabel {
    if (!_timeLabel) {
        _timeLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Light", 14) titleColor:HEX_RGB(@"#888888") textAlignment:ZZTextAlignmentLeft];
    }
    return _timeLabel;
}

- (UILabel *)statusLabel {
    if (!_statusLabel) {
        _statusLabel = [[UILabel alloc] init];
        _statusLabel.font = kCustomFont(@"PingFangSC-Light", 14);
        _statusLabel.textColor = HEX_RGB(@"#FFFFFF");
        _statusLabel.textAlignment = NSTextAlignmentCenter;
        _statusLabel.layer.cornerRadius = 11.5f;
        _statusLabel.layer.masksToBounds = YES;
    }
    return _statusLabel;
}


@end
